class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def levelOrderBottom(self, root):
        """
        :type root: TreeNode
        :rtype: List[List[int]]
        """
        if not root:
            return []
        node_list = []
        now_list = [root]
        while len(now_list) > 0:
            next_list = []
            now_val_list = []
            for item in now_list:
                now_val_list.append(item.val)
                if item.left:
                    next_list.append(item.left)
                if item.right:
                    next_list.append(item.right)
            now_list = next_list
            node_list.append(now_val_list)
        node_list.reverse()
        return node_list

